<?php


namespace app\api\controller;


use app\api\service\PharmacyBankAccountService;
use think\Controller;
use think\Request;

class PharmacyBank extends Controller
{
    private $pharmacyBankService;

    public function __construct(Request $request, PharmacyBankAccountService $pharmacyBankAccountService)
    {
        parent::__construct($request);

        $this->pharmacyBankService = $pharmacyBankAccountService;


    }


    /**
     * 绑定银行卡
     * @return \think\response\Json
     */
    public function postBankAccount(){

        $pharmacyId = $this->request->param("pharmacy_id");

        $bankAccount = $this->request->param('bank_account');

        $bankAccountName = $this->request->param('bank_account_name');

        $bankName = '';

        $r = $this->pharmacyBankService->addBankAccount($pharmacyId, $bankAccount, $bankAccountName, $bankName);

        return jsonResult([], '绑定成功！');

    }


    /**
     * 查询药店绑定的银行卡
     * @return \think\response\Json
     */
    public function getBankAccountList(){

        $pharmacyId = $this->request->param("pharmacy_id");

        $data = $this->pharmacyBankService->fetchBankAccount($pharmacyId);

        return jsonResult($data, '查询成功');
    }


    /**
     * 申请提现
     * @return \think\response\Json
     */
    public function postAddWithdraw(){

        $pharmacyId = $this->request->param('pharmacy_id');

        $bankAccountId = $this->request->param('bank_account_id');

        $amount = $this->request->param('amount');

        $r = $this->pharmacyBankService->addWithdraw($pharmacyId, $bankAccountId, $amount);

        return jsonResult([], '申请提现成功！');

    }


    /**
     * 获取可提现金额
     */
    public function getCanWithdrawAmount(){

        $pharmacyId = $this->request->param('pharmacy_id');


        $data = $this->pharmacyBankService->getCanWithdrawAmount($pharmacyId);

        return jsonResult(['can_withdraw_amount'=>$data]);

    }
}